<template>
  <view class="ikz-bid">
    <ikz-loading :css-data="loading_css"></ikz-loading>
    <view>
      <ikz-login :show-data="loginData" :css-data="login_css"></ikz-login>
    </view>
    <view>
      <ikz-ordertop :order-number="number_info"></ikz-ordertop>
    </view>

    <view class="ikz-ad" @click="goApply" v-if="userItem > 0 && user_info.is_business > 0 && user_info">
      <view class="ikz-merchant-entry"> 商家后台入口 </view>

    </view>

    <view class="ikz-menu-box" v-if="userItem > 0 && user_info.run_apply_status && user_info">
      <view class="ikz-menu-title">抢单员中心</view>
      <ikz-menu :user_info="user_info" :agent="false" :show-data="menu_data1" :css-data="menu_css"></ikz-menu>
    </view>
    <!-- v-if="userItem > 0 && user_info.is_business > 0 && user_info" -->
    <view class="ikz-menu-box" v-if="userItem > 0 && user_info.is_business > 0 && user_info">
      <view class="ikz-menu-title">商家中心</view>
      <ikz-merchant :user_info="user_info" :show-data="menu_data3" :css-data="menu_css"
        :is_business="user_info.is_business"></ikz-merchant>
    </view>
    <view class="ikz-menu-box" v-if="userItem > 0 && user_info.bind_agent_id > 0 && user_info">
      <view class="ikz-menu-title">代理中心</view>
      <ikz-menu :user_info="user_info" :agent="true" :show-data="menu_data2" :css-data="menu_css"></ikz-menu>
    </view>
    <view class="ikz-menu-box">
      <view class="ikz-menu-title">系统中心</view>
      <ikz-menu :show-data="menu_data" :css-data="menu_css"></ikz-menu>
    </view>
    <!-- 缺省 -->
    <view class="ikz-exit-but" @click="exitBut()" v-if="exitButTrue">退出登录</view>
    <!-- 备案号 -->
    <view class="main-statement" v-if="statement">备案号：{{ statement }}</view>
    <view class="default-height" style="width: 100%; height: 188rpx"></view>
    <ikz-tabbar :show-data="tabbar_Data"></ikz-tabbar>
  </view>
</template>

<script>
import ikzLoading from "@/pages/Component/Public/Loading/loading.vue";
import ikzMenu from "@/pages/Component/Public/Menu/public/menu/menu.vue";
// 商家
import ikzMerchant from "@/pages/Component/Public/Menu/public/merchant/merchant.vue";
import ikzLogin from "@/pages/Component/Public/Login/public/login/login.vue";
import ikzOrdertop from "@/pages/Component/Public/Ordertop/public/ordertop/ordertop.vue";
import ikzTabbar from "@/pages/Component/Public/tab-bar/tab-bar.vue";
var app = getApp();
import ikz from "@/pages/Common/tools.js";
export default {
  components: {
    ikzLoading,
    ikzMenu,
    ikzMerchant,
    ikzLogin,
    ikzOrdertop,
    ikzTabbar,
  },
  data() {
    return {
      exitButTrue: false,
      statement: "",
      tabbar_Data: {
        type: 0,
        list: [],
      },
      user_openinfo: app.globalData.user_openinfo,
      user_info: {},
      loginData: {},
      login_css: {
        background_color: "linear-gradient(to right,#F8C66D, #FBAB7E)",
        margin_top: 0,
        bg_border_radius: 0,
        width: 100,
      },
      loading_css: {
        display: "flex",
      },
      menu_data: {
        list: [
          {
            src: '/static/supermarket/user/icon_tel.png',
            title: '商家入驻',
            url: {
              path: "phone#" + app.globalData.customer_mobile,
              info: '无功能',
              mode: '5'
            }
          },
          {
            src: "/static/personal/about.png",
            title: "关于我们",
            url: {
              path: "/pages/Component/Module/Other/Program/about/index",
              info: "无功能",
              mode: "2",
            },
          },
          {
            src: "/static/personal/phone.png",
            title: "校内客服",
            url: {
              path: "phone#" + app.globalData.customer_mobile,
              info: "无功能",
              mode: "5",
            },
          },
          {
            src: "/static/personal/wechat.png",
            title: "平台客服",
            url: {
              path: "contact",
              info: "无功能",
              mode: "5",
            },
          },
          {
            src: "/static/personal/cooperation.png",
            title: "合作加盟",
            url: {
              path: "phone#" + app.globalData.customer_mobile,
              info: "无功能",
              mode: "5",
            },
          },
          {
            src: "/static/personal/agree.png",
            title: "用户协议",
            url: {
              path: "/pages/Component/Module/Other/Program/agreement/index",
              info: "无功能",
              mode: "2",
            },
          },
          {
            src: "/static/personal/help.png",
            title: "帮助中心",
            url: {
              path: "/pages/Component/Module/Other/Program/help/index/index",
              info: "无功能",
              mode: "2",
            },
          },
          {
            src: "/static/personal/feedback.png",
            title: "意见反馈",
            url: {
              path: "/pages/Component/Module/Other/Program/feedback/index",
              info: "无功能",
              mode: "2",
            },
          },
          {
            src: "/static/personal/address.png",
            title: "地址管理",
            url: {
              path: "/pages/Component/Module/Address/Program/myAddress/index",
              info: "token",
              mode: "2",
            },
          },
        ],
      },
      menu_data3: {
        list: [
          {
            src: "/static/personal/saoma.png",
            title: "自取扫码",
            url: {
              path: "/pages/Component/merchant/scanCode/index",
              info: "token",
              mode: "2",
              //   details: true,
            },
          },
          {
            src: "/static/personal/shop.png",
            title: "店铺订单",
            url: {
              path: "/pages/Component/merchant/order/index/index",
              info: "token",
              mode: "2",
              //   details: true,
            },
          },
          {
            src: "/static/personal/goods.png",
            title: "商品管理",
            url: {
              path: "/pages/Component/merchant/goods/index/index",
              info: "token",
              mode: "2",
            },
          },
          {
            src: "/static/personal/shop.png",
            title: "我的店铺",
            url: {
              path: "",
              info: "token",
              mode: "2",
              details: true,
            },
          },
          {
            src: "/static/personal/price.png",
            title: "佣金提现",
            url: {
              path: "/pages/Component/Module/Payment/Program/withdrawal/index/index?status=2",
              info: "token",
              mode: "2",
            },
          },
        ],
      },
      menu_data1: {
        list: [
          {
            src: "/static/personal/receive.png",
            title: "订单管理",
            url: {
              path: "/pages/Component/Module/Receiver/Program/home/index/index",
              info: "token",
              mode: "2",
            },
          },
          {
            src: "/static/personal/price.png",
            title: "佣金提现",
            url: {
              path: "/pages/Component/Module/Payment/Program/withdrawal/index/index?status=2",
              info: "token",
              mode: "2",
            },
          },
          {
            src: "/static/personal/order.png",
            title: "抢单大厅",
            url: {
              path: "/pages/Component/Module/Receiver/Program/order/index/index",
              info: "token",
              mode: "2",
            },
          },
          {
            src: "/static/personal/agree.png",
            title: "消息订阅",
            url: {
              path: "/pages/Personal/runSubscribe",
              info: "token",
              mode: "2",
            },
          },
        ],
      },
      menu_data2: {
        list: [
          {
            src: "/static/personal/about.png",
            title: "管理中心",
            url: {
              path: "/pages/Component/Module/Agent/Program/home/index/index",
              info: "token",
              mode: "2",
            },
          },
          {
            src: "/static/personal/price.png",
            title: "佣金提现",
            url: {
              path: "/pages/Component/Module/Payment/Program/withdrawal/index/index?status=3",
              info: "token",
              mode: "2",
            },
          },
          {
            src: "/static/personal/agree.png",
            title: "消息订阅",
            url: {
              path: "/pages/Personal/agentSubscribe",
              info: "token",
              mode: "2",
            },
          },
        ],
      },
      menu_css: {
        background_color: "#fff",
        bg_border_radius: 0,
        border_radius: "50%",
        color: "#888888",
        margin_top: 15,
        num: "4",
        width: 100,
      },
      number_info: {},
      run_apply_status: "",
      userItem: 0,
    };
  },
  created() {
    // var that = this;
  },
  onLoad() {
    uni.hideTabBar();
  },
  onShow() {
    this.getBaseinfo();
    if (uni.getStorageSync("userItem") == 1) {
      this.userItem = 1;
    } else {
      this.userItem = 0;
    }
    if (uni.getStorageSync("user_info") != "") {
      this.user_info = uni.getStorageSync("user_info");
    }

    this.tabbar_Data.list = app.globalData.tabBarInfo;
    this.tabbar_Data.type = app.globalData.tabBarInfo.length - 1;
    this.goApplyPhone();
    if (!uni.getStorageSync("user_info")) {
      this.loading_css.display = "none";
      return;
    }
    this.loginData.user_openinfo = uni.getStorageSync("user_info");
    this.loginData.mobile =
      app.globalData.mobile || uni.getStorageSync("user_info").mobile;
    this.userAuth((res) => {
      this.loading_css.display = "none";
    });
    this.orderNumber();
    if (uni.getStorageSync("local_user_session")) {
      this.exitButTrue = true;
      // this.getBaseinfo()
    } else {
      this.exitButTrue = false;
    }
  },
  onPullDownRefresh() {
    this.goApplyPhone();
    if (!uni.getStorageSync("user_info")) {
      uni.stopPullDownRefresh();
      return;
    }
    this.orderNumber();
    this.userAuth((res) => {
      uni.stopPullDownRefresh();
    });
  },

  onShareTimeline() { },
  onShareAppMessage() {
    // const promise = new Promise(resolve => {
    //   setTimeout(() => {
    //     resolve({
    //       title: '自定义转发标题',
    //       imageUrl:'https://xybaddon.maiwd.cn/shareButton.png',
    //     })
    //   }, 2000)
    // })
    return {
      title: app.globalData.share_info.share_title,
      path: "/pages/Home/index",
      imageUrl: app.globalData.share_info.share_img,
    };
  },
  methods: {
    goToSupermarket() {
      uni.navigateTo({
        url: "/pages/Component/supermarket/Program/index/index",
      });
    },
    //获取用户信息
    getBaseinfo() {
      var path = "/xyb/user/baseinfo";
      var data = {
        token: uni.getStorageSync("local_user_session"),
        app_plat: "MP-WEIXIN",
      };
      ikz.get(path, data, (res) => {
        // uni.showToast({
        //   title: res.data.data.user_info.user_id + "",
        //   duration: 2000,
        //   icon: "none",
        // });
        if (res.data.code) {
          console.log("值是", res.data.data);
          this.statement = res.data.data.applet_record_number;
          var user_address = res.data.data.user_address_list;
          if (user_address.length) {
            getApp().globalData.user_address.address_all = ""; //地址数据

            getApp().globalData.user_address.address_all = user_address; //地址数据
            for (var i = 0; i < user_address.length; i++) {
              if (user_address[i].defaults) {
                getApp().globalData.user_address.address_default =
                  user_address[i]; //默认地址
                getApp().globalData.user_address.address_current =
                  user_address[i]; //当前
              }
            }
            if (getApp().globalData.user_address.address_default == "") {
              getApp().globalData.user_address.address_default =
                user_address[0]; //默认地址
              getApp().globalData.user_address.address_current =
                user_address[0]; //当前
            }
          } else {
            getApp().globalData.user_address.address_all = ""; //地址数据
            getApp().globalData.user_address.address_default = ""; //默认地址
            getApp().globalData.user_address.address_current = ""; //当前
          }

          // uni.showModal({
          //     title: "提示",
          //     content: res.data.data.user_info.user_id,
          //     showCancel: false,
          //     success: function (res) {},
          //   });

          //设置用户信息
          if (res.data.data.user_info.nickname) {
            // console.log(res.data.data.user_info,'res.data.data.user_infores.data.data.user_info');
            getApp().globalData.user_openinfo = res.data.data.user_info || {};

            // console.log("2222222",res.data.data.user_info.user_id);
            this.user_info = res.data.data.user_info;
          } else {
            getApp().globalData.user_openinfo = {};
            this.userItem = 0;
          }
        }
      });
    },
    goApplyPhone() {
      var path = "/xyb/agent/phone";
      var data = {};
      if (uni.getStorageSync("local_user_session")) {
        ikz.post(path, data, (res) => {
          if (res.data.code) {
            (this.menu_data.list[1].url.path =
              "phone#" + (res.data.data && res.data.data.phone) || ""),
              this.$forceUpdate();
          } else {
            uni.showModal({
              title: "提示",
              content: res.data.msg,
              showCancel: false,
              success: function (res) { },
            });
          }
        });
      }
    },
    orderNumber() {
      var path = "/xyb/user/center_order_count";
      var data = {};
      ikz.post(path, data, (res) => {
        if (res.data.code) {
          this.number_info = res.data.data;
          this.$forceUpdate();
        } else {
          uni.showModal({
            title: "提示",
            content: res.data.msg,
            showCancel: false,
            success: function (res) { },
          });
        }
      });
    },
    // 退出登录
    exitBut() {
      uni.showModal({
        title: "系统提示",
        content: "确定要退出登录吗？",
        confirmColor: "#F8C66D",
        success: (res) => {
          if (res.confirm) {
            var path = "/user/logout";
            var data = {};
            ikz.post(path, data, (res) => {
              if (res.data.code) {
                uni.removeStorageSync("local_user_session");
                uni.removeStorageSync("user_info");
                uni.navigateTo({
                  url: "/pages/Personal/index",
                });
              } else {
                uni.showModal({
                  title: "提示",
                  content: res.data.msg,
                  showCancel: false,
                  success: function (res) { },
                });
              }
            });
          }
        },
      });
    },
    goApply() {
      uni.navigateTo({
        url: "/pages/Webview/index?path=https://dexinhebei.com/ZNqLOsRjSe.php/index/login",
      });
    },
    //请求页面数据
    userAuth(fn) {
      var path = "/xyb/user/auth";
      var data = {};
      ikz.post(path, data, (res) => {
        if (res.data.code) {
          this.user_openinfo.auth = res.data.data.auth;
          this.user_openinfo.bind_agent_id = res.data.data.bind_agent_id;
          this.user_openinfo.run_apply_status = res.data.data.run_apply_status;
          this.$forceUpdate(); // 添加强制更新
        } else {
          uni.showModal({
            title: "提示",
            content: res.data.msg,
            showCancel: false,
            success: function (res) { },
          });
        }
        fn();
        // if(that.pull_status){
        // 	this.$emit("change",'pull');
        // }
      });
    },
  },
};
</script>

<style lang="scss" scoped>
/* 颜色变量 */
$primary-color: #FBAB7E;
$secondary-color: #6D8CF8;
$text-color: #333;
$light-text: #666;
$border-color: #eee;
$white: #fff;
$shadow-color: rgba(0, 0, 0, 0.1);

/* 基础样式 */
.ikz-bid {
  width: 100%;
  min-height: 100vh;
  background: #f8f8f8;
  padding-bottom: 188rpx;
  box-sizing: border-box;
}

/* 菜单标题样式 */
.ikz-menu-title {
  position: relative;
  width: 100%;
  padding: 0 40rpx 20rpx;
  font-size: 32rpx;
  font-weight: 700;
  color: $text-color;
  box-sizing: border-box;

  &:before {
    content: "";
    position: absolute;
    left: 20rpx;
    top: 6rpx;
    height: 36rpx;
    width: 8rpx;
    background: $primary-color;
    border-radius: 4rpx;
  }
}

/* 菜单盒子样式 */
.ikz-menu-box {
  width: 94%;
  margin: 20rpx auto 0;
  padding: 30rpx 0;
  background: $white;
  border-radius: 16rpx;
  box-shadow: 0 4rpx 12rpx $shadow-color;
  overflow: hidden;
  transition: all 0.3s ease;

  &:active {
    transform: translateY(2rpx);
    box-shadow: 0 2rpx 6rpx $shadow-color;
  }
}

/* 商家入口按钮 */
.ikz-merchant-entry {
  width: 94%;
  margin: 20rpx auto;
  padding: 28rpx 0;
  background: linear-gradient(135deg, $secondary-color, lighten($secondary-color, 10%));
  color: $white;
  text-align: center;
  font-size: 32rpx;
  font-weight: 600;
  border-radius: 16rpx;
  box-shadow: 0 4rpx 12rpx rgba($secondary-color, 0.2);
  transition: all 0.2s ease;

  &:active {
    transform: translateY(2rpx);
    box-shadow: 0 2rpx 6rpx rgba($secondary-color, 0.2);
  }
}

/* 立即前往按钮 */
.ikz-menu-box view[style*="color: #fbab7e"] {
  margin: 20rpx 30rpx 0;
  padding: 20rpx 0;
  background: rgba($primary-color, 0.1);
  color: $primary-color;
  font-size: 30rpx;
  border-radius: 12rpx;
  transition: all 0.2s ease;

  &:active {
    background: rgba($primary-color, 0.2);
  }
}

/* 退出登录按钮 */
.ikz-exit-but {
  width: 94%;
  margin: 30rpx auto 0;
  padding: 28rpx 0;
  background: $white;
  color: $primary-color;
  font-size: 32rpx;
  font-weight: 600;
  text-align: center;
  border-radius: 16rpx;
  box-shadow: 0 4rpx 12rpx $shadow-color;
  transition: all 0.2s ease;

  &:active {
    transform: translateY(2rpx);
    box-shadow: 0 2rpx 6rpx $shadow-color;
  }
}

/* 备案号样式 */
.main-statement {
  margin-top: 48rpx;
  padding: 20rpx 0;
  font-size: 24rpx;
  color: $light-text;
  text-align: center;
  line-height: 1.6;
}

/* 默认高度容器 */
.default-height {
  width: 100%;
  height: 188rpx;
}

/* 响应式调整 */
@media (max-width: 480px) {

  .ikz-menu-box,
  .ikz-merchant-entry,
  .ikz-exit-but {
    width: 92%;
  }
}
</style>